package com.bw.tap;


import android.graphics.Color;
import android.view.View;

import androidx.lifecycle.Observer;

import com.bw.lib_core.mvvm.view.BaseActivity;
import com.bw.lib_core.mvvm.viewmodel.DefViewModel;
import com.bw.tap.adapter.CommunityAdapter;
import com.bw.tap.base.BaseBarActivity;
import com.bw.tap.base.TitleBarActivity;
import com.bw.tap.base.TitleRightBtn;
import com.bw.tap.bean.Community;
import com.bw.tap.databinding.ActivityMainBinding;

import java.util.List;

public class MainActivity extends TitleBarActivity<ActivityMainBinding, MainViewModel> {

    private CommunityAdapter communityAdapter;

    @Override
    public int bandingLayout() {
        return R.layout.activity_main;
    }

    @Override
    public int initVariableId() {
        return 0;
    }

    @Override
    public void initBar() {
        super.initBar();
        registerBack();
        setTitle("");
        addRightBtn(new TitleRightBtn.Builder().addIcon(1).addName(1).build());
    }

    @Override
    public void initObserver() {
        mViewModel.data.observe(this, new Observer<List<Community>>() {
            @Override
            public void onChanged(List<Community> communities) {
                //数据维护
                if (mDataBinding.recyclerView.getAdapter() == null) {
                    communityAdapter = new CommunityAdapter();
                    mDataBinding.recyclerView.setAdapter(communityAdapter);
                }
                communityAdapter.getData().addAll(communities);
                communityAdapter.notifyDataSetChanged();
            }
        });

        mDataBinding.recyclerView.setOnScrollChangeListener(new View.OnScrollChangeListener() {
            @Override
            public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
                //边界判断
                //滑动对呀响应->改变对应View属性 （高度，偏移，缩放，JY）
            }
        });
    }
}